<?php
/**
 * @package    indie-bookstore
 * @subpackage bookstore
 * @author David Neimeyer davidneimeyer@gmail.com
 * components/com_bookstore/views/view.html.php
 * @link http://indie-bookstore.googlecode.com/
 * @license    GNU/GPL
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Bookstore Component
 *
 * @package    indie-bookstore
 * @subpackage bookstore
 */

class bookstoreViewbookstore extends JView
{
	/**
	 * basic display
	 *
	 * @param string $tpl
	 */
	function display($tpl = null){
		global $mainframe,$option;
		$model = $this->getModel();

		/**
		 * @var $view_todo results of what the model has interpreted as the user request
		 * @review is this really the job of the model? shouldn't the view (or possibly
		 *  the controller) be handling that?
		 * @note $model->inspectRequest() currently calls $model->handleRequest()
		 */
		$view_todo = $model->inspectRequest();
		switch($view_todo){
			case '1': //empty search, landing page
				$terms = JRequest::getVar('terms',null);
				JRequest::setVar('terms',NULL);
				parent::display($tpl);
				break;
			case '0':
			default:
				/**
				 * @todo $model should use a general getData like method, this is obviously a shortcut of sorts
				 */
				$items =  $model->getLocalResults2();

				/*
					echo '<!-- ';
					var_dump(JRequest::getVar('terms', NULL) );
					echo ' -->';
					*/

				/**
				 *  pagination
				 *
				 *  @review this helper file/function is a bug work-around and 'should' be obsolete with j1.5RC4+
				 */
				$file = JPATH_COMPONENT.DS.'helpers'.DS.'pagination.php';
				require_once($file);
				$pagination = NewgetPagesLinks($model->pageNav, array('query_type'=>'pageNav') );//'&terms='.$qterms);

					
				$this->assignRef('pageNav',$pagination);
				$this->assignRef('items', $items);
				parent::display($tpl);

		}//end switch
		JHTML::stylesheet('modal.css');
		//FIXME this path should be a defined in a config, with default fallback
		//@review consider including this in html or bundle js code with others js;
		// ex: 'component'.DS.JCOMPONENT.DS.'js'.DS
		JHTML::script('show_detail.js', 'components/com_bookstore/js/');
		JHTML::script('modal.js');
	}//end display method
}//end view class
?>